package com.asdan.seededu.web.controller;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.asdan.seededu.entity.security.SubProject;
import com.asdan.seededu.entity.security.SubProjectStep;
import com.asdan.seededu.entity.security.User;
import com.asdan.seededu.entity.security.Userdata;
import com.asdan.seededu.front.service.ISWEEPService;
import com.asdan.seededu.front.service.IsweepStep2Service;
import com.asdan.seededu.front.service.Product01Service;
import com.asdan.seededu.front.service.ProjectService;
import com.asdan.seededu.front.service.impl.ISWEEPServiceImp;
import com.asdan.seededu.front.service.impl.IsweepStep2ServiceImpl;
import com.asdan.seededu.front.service.impl.Product01ServiceImp;
import com.asdan.seededu.front.service.impl.ProjectServiceImpl;
import com.demo2do.core.web.interceptor.MenuSetting;

@Controller
@MenuSetting("menu-project")
@RequestMapping("isweepfront")
public class ISWEEPFrontController {
	/**
	 * Display project page
	 * 
	 * @return
	 */
	//用户个人信息
	@RequestMapping(value="{spid}/{stepid}/detail",method=RequestMethod.GET)
	public String detail(@PathVariable String spid,@PathVariable String stepid,Model model,HttpServletRequest req) {
		
		//通过session获取用户id,获取service函数
		String uid=(String) req.getSession().getAttribute("userid");
		ISWEEPService is=new ISWEEPServiceImp();
		//获取流程信息
		List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
		
		SubProjectStep subProjectStep=(SubProjectStep) list.get(0);
		stepid=Integer.toString(subProjectStep.getStepid());//初始化stepid，为信息确认时的stepid
		
		//判断uid,spid,stepid是否合法
		String tmp =is.prepare("detail",uid,spid,stepid);
		if(!tmp.equals("OK"))
		{
			if(tmp.equals("notlogin"))
			{
				return "redirect:/sign_In.jsp";
			}
			model.addAttribute("msg",tmp);
			return "front_ISWEEP/message_Error";
		}	
		//转换成int型
		int Uid=Integer.parseInt(uid);
		int Pid=Integer.parseInt(spid);
		int Stepid=Integer.parseInt(stepid);
		//判断是否是“已完成此步骤”，或者“正要做此步骤”，或者是“未开始此步骤”;
		String redirect_page = "";
		int CurStep = is.getCurrentStepid(Uid,Pid);
		model.addAttribute("CurStep",CurStep);//当前setpid传到页面
		
		System.out.println("Curstep:"+CurStep);
		System.out.println("stepid:"+Integer.parseInt(stepid));
		
		if(CurStep  == Integer.parseInt(stepid))
		{
			if(is.HasData(Uid,Pid))//user_data中有数据
			{
				model.addAttribute("Finished","doing");//从userdata取数据
				User user=is.getData(Integer.parseInt(uid), Integer.parseInt(spid));
				model.addAttribute("info",user);
				redirect_page = "front_ISWEEP/step1_ISWEEP_Infoconfirm";
			}
			else//user_data中没有数据
			{
				model.addAttribute("Finished","notstart");
				User user=is.getInfo(Integer.parseInt(uid), Integer.parseInt(spid)) ;
				model.addAttribute("info",user);
				redirect_page = "front_ISWEEP/step1_ISWEEP_Infoconfirm";	
			}
		}
		else if(CurStep  > Stepid )//已完成此步骤
		{
			model.addAttribute("Finished","done");//从userdata取数据
			User user=is.getData(Integer.parseInt(uid), Integer.parseInt(spid));
			model.addAttribute("info",user);
			redirect_page = "front_ISWEEP/step1_ISWEEP_Infoconfirm_Done";
		}
		else
		{
			model.addAttribute("msg","出现神奇错误!请通知管理员!^_^!");
			return "front_ISWEEP/message_Error";
		}
		//获取子项目信息
		Product01Service p1s = new Product01ServiceImp();
		SubProject subpro=new SubProject();
		subpro=p1s.getsubpro(Uid, Pid);
		model.addAttribute("subpro",subpro);
		
		model.addAttribute("steplist",list);
		model.addAttribute("uid",uid);
		model.addAttribute("spid",spid);
		model.addAttribute("stepid",stepid);
		//打印本函数日志结果
		is.printlog("detail",uid,spid,stepid,list);
		//返回应该跳转到的页面
		return redirect_page;
	}

	@RequestMapping(value="/saveInfo",method=RequestMethod.POST)
	public String saveInfo(String stepid,String spid, String name, String sex,
			String firstname, String lastname, String birthday,String idcard,
			String schoolname, String grade, String email, String phone,
			String qq, String address, String postcode, String fathername,
			String fatheremail,String fatherphone, String mothername,String motherphone, String motheremail,String isbookhotel,Model model,HttpServletRequest req) {
		
		//通过session获取用户id,获取service函数
		String uid=(String) req.getSession().getAttribute("userid");
		ISWEEPService is=new ISWEEPServiceImp();
		//判断uid,spid,stepid是否合法
		String tmp = is.prepare("saveInfo",uid,spid,stepid);
		if(!tmp.equals("OK"))
		{
			if(tmp.equals("notlogin"))
			{
				return "redirect:/sign_In.jsp";
			}
			model.addAttribute("msg",tmp);
			return "front_ISWEEP/message_Error";
		}	
		//转换成int型
		int Uid=Integer.parseInt(uid);
		int Pid=Integer.parseInt(spid);
		int Stepid=Integer.parseInt(stepid);
		

		boolean isSave=is.saveInfo(Stepid,Uid, Pid, name, sex, firstname, lastname, birthday, idcard,schoolname, grade, email, phone, qq, address, postcode, fathername, fatheremail, fatherphone, mothername, motherphone, motheremail,isbookhotel);
		if( isSave){
			model.addAttribute("message","信息保存成功");
		}else
			model.addAttribute("message","信息保存失败");
	
		//获取子项目信息
		Product01Service p1s = new Product01ServiceImp();
		SubProject subpro=new SubProject();
		subpro=p1s.getsubpro(Uid, Pid);
		model.addAttribute("subpro",subpro);
		//获取流程信息
		List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
		model.addAttribute("steplist",list);
		model.addAttribute("uid",uid);
		model.addAttribute("spid",spid);
		//打印本函数日志结果
		is.printlog("detail",uid,spid,stepid,list);
	
		return detail(spid, stepid, model, req);
	}
	
	//提交个人信息
		@RequestMapping(value="/submitInfo",method=RequestMethod.POST)
		public String submitInfo(String stepid, String spid, String name, String sex,
				String firstname, String lastname, String birthday,String idcard,
				String schoolname, String grade, String email, String phone,
				String qq, String address, String postcode, String fathername,
				String fatheremail,String fatherphone, String mothername,String motherphone,
				String motheremail,String isbookhotel,Model model,HttpServletRequest req) {
			//通过session获取用户id,获取service函数
			String uid=(String) req.getSession().getAttribute("userid");
			ISWEEPService is=new ISWEEPServiceImp();
			//判断uid,spid,stepid是否合法
			String tmp = is.prepare("submitInfo",uid,spid,stepid);
			if(!tmp.equals("OK"))
			{
				if(tmp.equals("notlogin"))
				{
					return "redirect:/sign_In.jsp";
				}
				model.addAttribute("msg",tmp);
				return "front_ISWEEP/message_Error";
			}	
			//转换成int型
			int Uid=Integer.parseInt(uid);
			int Pid=Integer.parseInt(spid);
			int Stepid=Integer.parseInt(stepid);
			
			boolean isSave=is.saveInfo(Stepid+1,Uid, Pid, name, sex, firstname, lastname, birthday,idcard, schoolname, grade, email, phone, qq, address, postcode, fathername, fatheremail, fatherphone, mothername, motherphone, motheremail,isbookhotel);
			if( isSave){
				model.addAttribute("message","提交成功");
			}else
				model.addAttribute("message","提交失败");

			//获取子项目信息
			Product01Service p1s = new Product01ServiceImp();
			SubProject subpro=new SubProject();
			subpro=p1s.getsubpro(Uid, Pid);
			model.addAttribute("subpro",subpro);
			
			
			//获取流程信息
			List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
			model.addAttribute("steplist",list);
			model.addAttribute("uid",uid);
			model.addAttribute("spid",spid);
			//打印本函数日志结果
			is.printlog("detail",uid,spid,stepid,list);
			
			return this.team(spid,String.valueOf(Stepid+1), model,req);
		}
		
		@RequestMapping(value="{spid}/{stepid}/toNextStep",method=RequestMethod.GET)
		public String toNextStep(@PathVariable String spid,@PathVariable String stepid,Model model,HttpServletRequest req) {
			
			String uid=(String) req.getSession().getAttribute("userid");
			ProjectService ps = new ProjectServiceImpl() ;
			ps.toNextStep(Integer.parseInt(stepid), Integer.parseInt(uid)) ;
			return detail(spid, stepid, model, req);

		}
		@RequestMapping(value="{spid}/{stepid}/Team",method=RequestMethod.GET)
		public String team(@PathVariable String spid,@PathVariable String stepid,Model model,HttpServletRequest req) {
			
			String uid=(String) req.getSession().getAttribute("userid");
			IsweepStep2Service  iss = new IsweepStep2ServiceImpl() ;
			Userdata ud = iss.getUserdata(Integer.parseInt(uid), Integer.parseInt(spid)) ;
			int teamid = ud.getTeam().getTeamid() ;
			int ifleader = ud.getIsleader() ;
			model.addAttribute("uid",uid);
			model.addAttribute("spid",spid);
			model.addAttribute("stepid",stepid);
			
			ISWEEPService is=new ISWEEPServiceImp();
			int CurStep = is.getCurrentStepid(Integer.parseInt(uid),Integer.parseInt(spid));
			model.addAttribute("CurStep",CurStep);//当前setpid传到页面
			//获取流程信息
			List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
			model.addAttribute("steplist",list);
			//打印本函数日志结果
			is.printlog("detail",uid,spid,stepid,list);
			
			if(teamid==0){
				return "front_ISWEEP/step2_ISWEEP_selected";
			}else{
				if(ifleader==1){
					 iss = new IsweepStep2ServiceImpl() ;
					 model.addAttribute("ulist", iss.getUserdata(ud.getUser().getSchoolname(), Integer.parseInt(spid))) ;
					 iss = new IsweepStep2ServiceImpl() ;
					 model.addAttribute("team", iss.getTeam(Integer.parseInt(uid), Integer.parseInt(spid))) ;
					return "front_ISWEEP/step2_ISWEEP_captain";
				}else{
					 iss = new IsweepStep2ServiceImpl() ;
					 model.addAttribute("team", iss.getTeam(Integer.parseInt(uid), Integer.parseInt(spid))) ;
					return "front_ISWEEP/step2_ISWEEP_member";
				}
			}
			

		}
		@RequestMapping(value="{spid}/{stepid}/createTeam",method=RequestMethod.GET)
		public String createTeam(@PathVariable String spid,@PathVariable String stepid,Model model,HttpServletRequest req) {
			
			//通过session获取用户id,获取service函数
			String uid=(String) req.getSession().getAttribute("userid");
			IsweepStep2Service  iss = new IsweepStep2ServiceImpl() ;
			Userdata ud = iss.getUserdata(Integer.parseInt(uid), Integer.parseInt(spid)) ;
			if(ud.getTeam().getTeamid()==0){
				iss = new IsweepStep2ServiceImpl() ;
				if(!iss.createTeam(Integer.parseInt(uid), Integer.parseInt(spid))) // 创建成功
					return this.team(spid, stepid, model, req);
			}
				iss = new IsweepStep2ServiceImpl() ;
				model.addAttribute("ulist", iss.getUserdata(ud.getUser().getSchoolname(), Integer.parseInt(spid))) ;
				iss = new IsweepStep2ServiceImpl() ;
				model.addAttribute("team", iss.getTeam(Integer.parseInt(uid), Integer.parseInt(spid))) ;
				return this.team(spid, stepid, model, req);

		}
		@RequestMapping(value="{spid}/{stepid}/{uid}/{teamid}/addUserToTeam",method=RequestMethod.GET)
		public String addUserToTeam( @PathVariable String spid,@PathVariable String stepid,@PathVariable String uid,@PathVariable String teamid ,Model model,HttpServletRequest req) {
			//通过session获取用户id,获取service函数
			IsweepStep2Service  iss = new IsweepStep2ServiceImpl() ;
			iss.addUserToTeam(Integer.parseInt(uid), Integer.parseInt(spid), Integer.parseInt(teamid)) ;
			return this.team(spid, stepid, model, req);

		}
		@RequestMapping(value="{spid}/{stepid}/{uid}/{teamid}/removeUserToTeam",method=RequestMethod.GET)
		public String removeUserToTeam( @PathVariable String spid,@PathVariable String stepid,@PathVariable String uid,@PathVariable String teamid ,Model model,HttpServletRequest req) {
			//通过session获取用户id,获取service函数
			IsweepStep2Service  iss = new IsweepStep2ServiceImpl() ;
			iss.removeUserFromTeam(Integer.parseInt(uid), Integer.parseInt(spid)) ;
			return this.team(spid, stepid, model, req);

		}
		@RequestMapping(value="{spid}/{stepid}/{uid}/{teamid}/dismissTeam",method=RequestMethod.GET)
		public String dismissTeam( @PathVariable String spid,@PathVariable String stepid,@PathVariable String uid,@PathVariable String teamid ,Model model,HttpServletRequest req) {
			//通过session获取用户id,获取service函数
			IsweepStep2Service  iss = new IsweepStep2ServiceImpl() ;
			iss.dismissTeam(Integer.parseInt(spid), Integer.parseInt(teamid)) ;
			return this.team(spid, stepid, model, req);

		}
		
		@RequestMapping(value="/{spid}/{stepid}/joinTeam",method=RequestMethod.GET)
		public String joinTeam(@PathVariable String spid ,@PathVariable String stepid ,Model model,HttpServletRequest req) {
			String uid=(String) req.getSession().getAttribute("userid");
			IsweepStep2Service  iss = new IsweepStep2ServiceImpl() ;
			Userdata ud = iss.getUserdata(Integer.parseInt(uid), Integer.parseInt(spid)) ;
			model.addAttribute("tlist",iss.getTeams(ud.getUser().getSchoolname(), Integer.parseInt(spid))) ;
			return "front_ISWEEP/step2_ISWEEP_join";
		}
		
		
		@RequestMapping(value="{spid}/{stepid}/show_profile",method=RequestMethod.GET)
		public String show_profile(@PathVariable String spid,@PathVariable String stepid,Model model,HttpServletRequest req){
			
			//通过session获取用户id,获取service函数
			String uid=(String) req.getSession().getAttribute("userid");
			ISWEEPService is=new ISWEEPServiceImp();
			//判断uid,spid,stepid是否合法
			String tmp = is.prepare("show_profile",uid,spid,stepid);
			if(!tmp.equals("OK")){
				if(tmp.equals("notlogin"))
				{
					return "redirect:/sign_In.jsp";
				}
				model.addAttribute("msg",tmp);
				return "front_ISWEEP/message_Error";
			}	
			//转换成int型
			int Uid=Integer.parseInt(uid);
			int Pid=Integer.parseInt(spid);
			int Stepid=Integer.parseInt(stepid);
			//判断是否是“已完成此步骤”，或者“正要做此步骤”，或者是“未开始此步骤”;
			String redirect_page = "";
			int CurStep = is.getCurrentStepid(Uid,Pid);
			model.addAttribute("CurStep",CurStep);//当前setpid传到页面
			
			System.out.println("Curstep:"+CurStep);
			System.out.println("stepid:"+Integer.parseInt(stepid));

			if(CurStep> Stepid )//完成此步骤
			{
				model.addAttribute("Finished","done");//从userdata取数据
				User profile=is.getData(Integer.parseInt(uid), Integer.parseInt(spid));
				model.addAttribute("profile",profile);
				
				redirect_page = "front_ISWEEP/step3_ISWEEP_Scienceprofile_Done";
			}
			else if(CurStep == Integer.parseInt(stepid))
			{
				model.addAttribute("Finished","doing");//从userdata取数据
				
				User profile=is.getData(Integer.parseInt(uid), Integer.parseInt(spid));
				model.addAttribute("profile",profile);

				redirect_page = "front_ISWEEP/step3_ISWEEP_Scienceprofile";
			}
			else
			{
				model.addAttribute("Finished","notstart");
				model.addAttribute("msg","请先完成之前的步骤！");
				redirect_page = "front_ISWEEP/message_Error";//提示之前步骤未完成
			}
			
			
			//获取子项目信息
			Product01Service p1s = new Product01ServiceImp();
			SubProject subpro=new SubProject();
			subpro=p1s.getsubpro(Uid, Pid);
			model.addAttribute("subpro",subpro);
			//获取流程信息
			List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
			model.addAttribute("steplist",list);
			model.addAttribute("uid",uid);
			model.addAttribute("spid",spid);
			model.addAttribute("stepid",stepid);
			//打印本函数日志结果
			is.printlog("show_profile",uid,spid,stepid,list);
			//返回应该跳转到的页面
			return redirect_page;
		}
		
		//读，显示出行信息
			@RequestMapping(value="{spid}/{stepid}/show_outprepare",method=RequestMethod.GET)
			public String show_outprepare(@PathVariable String spid,@PathVariable String stepid,Model model,HttpServletRequest req){
				
				//通过session获取用户id,获取service函数
				String uid=(String) req.getSession().getAttribute("userid");
				ISWEEPService is=new ISWEEPServiceImp();
				//判断uid,spid,stepid是否合法
				String tmp = is.prepare("show_outprepare",uid,spid,stepid);
				if(!tmp.equals("OK"))
				{
					if(tmp.equals("notlogin"))
					{
						return "redirect:/sign_In.jsp";
					}
					model.addAttribute("msg",tmp);
					return "front_ISWEEP/message_Error";
				}	
				//转换成int型
				int Uid=Integer.parseInt(uid);
				int Pid=Integer.parseInt(spid);
				int Stepid=Integer.parseInt(stepid);
				//判断是否是“已完成此步骤”，或者“正要做此步骤”，或者是“未开始此步骤”;
				String redirect_page = "";
				int CurStep = is.getCurrentStepid(Uid,Pid);
				model.addAttribute("CurStep",CurStep);//当前setpid传到页面
				
				System.out.println("Curstep:"+CurStep);
				System.out.println("stepid:"+Integer.parseInt(stepid));
				if(CurStep> Stepid || CurStep == -1)//完成此步骤
				{
					model.addAttribute("Finished","done");//从userdata取数据
					User out=is.getData(Integer.parseInt(uid), Integer.parseInt(spid));
					model.addAttribute("out",out);
					
					redirect_page = "front_ISWEEP/step4_ISWEEP_Outprepare_Done";
				}
				else if(CurStep == Integer.parseInt(stepid))
				{
					model.addAttribute("Finished","doing");//从userdata取数据
					
					User out=is.getData(Integer.parseInt(uid), Integer.parseInt(spid));
					model.addAttribute("out",out);

					redirect_page = "front_ISWEEP/step4_ISWEEP_Outprepare";
				}
				else
				{
					model.addAttribute("Finished","notstart");
					model.addAttribute("msg","请先完成之前的步骤！");
					redirect_page = "front_ISWEEP/message_Error";
				}
				//获取子项目信息
				Product01Service p1s = new Product01ServiceImp();
				SubProject subpro=new SubProject();
				subpro=p1s.getsubpro(Uid, Pid);
				model.addAttribute("subpro",subpro);
				//获取流程信息
				List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
				model.addAttribute("steplist",list);
				model.addAttribute("uid",uid);
				model.addAttribute("spid",spid);
				model.addAttribute("stepid",stepid);
				//打印本函数日志结果
				is.printlog("show_outprepare",uid,spid,stepid,list);
				//返回应该跳转到的页面
				return redirect_page;
			}
			
		//写，保存出行信息
		@RequestMapping(value="/outprepare",method=RequestMethod.POST)
		public String outprepare(String stepid, String spid, String hb_cc,String datapicker,
				String arriveAddress, String jiaotongxinxi, String paifangxinxi,Model model,HttpServletRequest req){
			//通过session获取用户id,获取service函数
			String uid=(String) req.getSession().getAttribute("userid");
			ISWEEPService is=new ISWEEPServiceImp();
			//判断uid,spid,stepid是否合法
			String tmp = is.prepare("outprepare",uid,spid,stepid);
			if(!tmp.equals("OK"))
			{
				if(tmp.equals("notlogin"))
				{
					return "redirect:/sign_In.jsp";
				}
				model.addAttribute("msg",tmp);
				return "front_ISWEEP/message_Error";
			}	
			//转换成int型
			int Uid=Integer.parseInt(uid);
			int Pid=Integer.parseInt(spid);
			int Stepid=Integer.parseInt(stepid);
			
			boolean isPrepare=is.outprepare(Stepid,Uid, Pid, hb_cc,datapicker, arriveAddress, jiaotongxinxi, paifangxinxi);
			if( isPrepare){
				model.addAttribute("message","出行准备成功");
			}else
				model.addAttribute("message","出行准备失败");
			
			//获取子项目信息
			Product01Service p1s = new Product01ServiceImp();
			SubProject subpro=new SubProject();
			subpro=p1s.getsubpro(Uid, Pid);
			model.addAttribute("subpro",subpro);
			//获取流程信息
			List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
			model.addAttribute("steplist",list);
			model.addAttribute("uid",uid);
			model.addAttribute("spid",spid);
			//打印本函数日志结果
			is.printlog("detail",uid,spid,stepid,list);
			
			return show_feedback(spid,String.valueOf(Stepid+1),model,req);
			
		}
		
		//读，反馈评价
		@RequestMapping(value="{spid}/{stepid}/show_feedback",method=RequestMethod.GET)
		public String show_feedback(@PathVariable String spid,@PathVariable String stepid,Model model,HttpServletRequest req){
			
			//通过session获取用户id,获取service函数
			String uid=(String) req.getSession().getAttribute("userid");
			ISWEEPService is=new ISWEEPServiceImp();
			//判断uid,spid,stepid是否合法
			String tmp = is.prepare("show_feedback",uid,spid,stepid);
			if(!tmp.equals("OK"))
			{
				if(tmp.equals("notlogin"))
				{
					return "redirect:/sign_In.jsp";
				}
				model.addAttribute("msg",tmp);
				return "front_ISWEEP/message_Error";
			}	
			//转换成int型
			int Uid=Integer.parseInt(uid);
			int Pid=Integer.parseInt(spid);
			int Stepid=Integer.parseInt(stepid);
			//判断是否是“已完成此步骤”，或者“正要做此步骤”，或者是“未开始此步骤”;
			String redirect_page = "";
			int CurStep = is.getCurrentStepid(Uid,Pid);
			model.addAttribute("CurStep",CurStep);//当前setpid传到页面
			
			System.out.println("Curstep:"+CurStep);
			System.out.println("stepid:"+Integer.parseInt(stepid));
			if(CurStep > Stepid || CurStep == -1)//完成此步骤
			{
				model.addAttribute("Finished","done");//从userdata取数据
				User back=is.getData(Integer.parseInt(uid), Integer.parseInt(spid));
				model.addAttribute("back",back);
				
				redirect_page = "front_ISWEEP/step5_ISWEEP_Feedback_Done";
			}
			else if(CurStep == Integer.parseInt(stepid))
			{
				model.addAttribute("Finished","doing");//从userdata取数据
				
				User back=is.getData(Integer.parseInt(uid), Integer.parseInt(spid));
				model.addAttribute("back",back);

				redirect_page = "front_ISWEEP/step5_ISWEEP_Feedback";
			}
			else
			{
				model.addAttribute("Finished","notstart");
				model.addAttribute("msg","请先完成之前的步骤！");
				redirect_page = "front_ISWEEP/message_Error";//提示之前步骤未完成
			}
			
			//获取子项目信息
			Product01Service p1s = new Product01ServiceImp();
			SubProject subpro=new SubProject();
			subpro=p1s.getsubpro(Uid, Pid);
			model.addAttribute("subpro",subpro);
			//获取流程信息
			List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
			model.addAttribute("steplist",list);
			model.addAttribute("uid",uid);
			model.addAttribute("spid",spid);
			model.addAttribute("stepid",stepid);
			//打印本函数日志结果
			is.printlog("show_feedback",uid,spid,stepid,list);
			//返回应该跳转到的页面
			return redirect_page;
		}
				
			//写，反馈评价
			@RequestMapping(value="/feedback",method=RequestMethod.POST)
			public String feedback(String stepid,String spid,String fkpjbz,Model model,HttpServletRequest req){
				//通过session获取用户id,获取service函数
				String uid=(String) req.getSession().getAttribute("userid");
				ISWEEPService is=new ISWEEPServiceImp();
				//判断uid,spid,stepid是否合法
				String tmp = is.prepare("feedback",uid,spid,stepid);
				if(!tmp.equals("OK"))
				{
					if(tmp.equals("notlogin"))
					{
						return "redirect:/sign_In.jsp";
					}
					model.addAttribute("msg",tmp);
					return "front_ISWEEP/message_Error";
				}	
				//转换成int型
				int Uid=Integer.parseInt(uid);
				int Pid=Integer.parseInt(spid);
				int Stepid=Integer.parseInt(stepid);
				
				boolean isPrepare=is.saveFeedback(Stepid,Uid,Pid, fkpjbz);
				if( isPrepare){
					model.addAttribute("message","反馈评价成功");
				}else
					model.addAttribute("message","反馈评价失败");
				
				//获取子项目信息
				Product01Service p1s = new Product01ServiceImp();
				SubProject subpro=new SubProject();
				subpro=p1s.getsubpro(Uid, Pid);
				model.addAttribute("subpro",subpro);
				//获取流程信息
				List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
				model.addAttribute("steplist",list);
				model.addAttribute("uid",uid);
				model.addAttribute("spid",spid);
				//打印本函数日志结果
				is.printlog("detail",uid,spid,stepid,list);
				
				return show_result(spid,String.valueOf(Stepid+1),model, req);
				
			}
			
			//读，获取结果
			@RequestMapping(value="{spid}/{stepid}/show_result",method=RequestMethod.GET)
			public String show_result(@PathVariable String spid,@PathVariable String stepid,Model model,HttpServletRequest req){
				
				//通过session获取用户id,获取service函数
				String uid=(String) req.getSession().getAttribute("userid");
				ISWEEPService is=new ISWEEPServiceImp();
				//判断uid,spid,stepid是否合法
				String tmp = is.prepare("show_result",uid,spid,stepid);
				if(!tmp.equals("OK"))
				{
					if(tmp.equals("notlogin"))
					{
						return "redirect:/sign_In.jsp";
					}
					model.addAttribute("msg",tmp);
					return "front_ISWEEP/message_Error";
				}	
				//转换成int型
				int Uid=Integer.parseInt(uid);
				int Pid=Integer.parseInt(spid);
				int Stepid=Integer.parseInt(stepid);
				//判断是否是“已完成此步骤”，或者“正要做此步骤”，或者是“未开始此步骤”;
				String redirect_page = "";
				int CurStep = is.getCurrentStepid(Uid,Pid);
				model.addAttribute("CurStep",CurStep);//当前setpid传到页面
				
				System.out.println("Curstep:"+CurStep);
				System.out.println("stepid:"+Integer.parseInt(stepid));
				if(CurStep  > Stepid || CurStep == -1)//完成此步骤
				{
					model.addAttribute("Finished","done");//从userdata取数据
					User result=is.getData(Integer.parseInt(uid), Integer.parseInt(spid));
					model.addAttribute("result",result);
					
					redirect_page = "front_ISWEEP/step6_ISWEEP_Getresult_Done";
				}
				else if(CurStep == Integer.parseInt(stepid))
				{
					model.addAttribute("Finished","doing");//从userdata取数据
					
					User result=is.getData(Integer.parseInt(uid), Integer.parseInt(spid));
					model.addAttribute("result",result);

					redirect_page = "front_ISWEEP/step6_ISWEEP_Getresult";
				}
				else
				{
					model.addAttribute("Finished","notstart");
					model.addAttribute("msg","请先完成之前的步骤！");
					redirect_page = "front_ISWEEP/message_Error";//提示之前步骤未完成
				}
				
				//获取子项目信息
				Product01Service p1s = new Product01ServiceImp();
				SubProject subpro=new SubProject();
				subpro=p1s.getsubpro(Uid, Pid);
				model.addAttribute("subpro",subpro);
				//获取流程信息
				List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
				model.addAttribute("steplist",list);
				model.addAttribute("uid",uid);
				model.addAttribute("spid",spid);
				model.addAttribute("stepid",stepid);
				//打印本函数日志结果
				is.printlog("show_result",uid,spid,stepid,list);
				//返回应该跳转到的页面
				return redirect_page;
				
			}
			
		//写，获取结果
		@RequestMapping(value="/result",method=RequestMethod.GET)
		public String result(String stepid,String spid,String hjqk,String hqjgbz,Model model,HttpServletRequest req){
			//通过session获取用户id,获取service函数
			String uid=(String) req.getSession().getAttribute("userid");
			ISWEEPService is=new ISWEEPServiceImp();
			//判断uid,spid,stepid是否合法
			String tmp = is.prepare("result",uid,spid,stepid);
			if(!tmp.equals("OK"))
			{
				if(tmp.equals("notlogin"))
				{
					return "redirect:/sign_In.jsp";
				}
				model.addAttribute("msg",tmp);
				return "front_ISWEEP/message_Error";
			}	
			//转换成int型
			int Uid=Integer.parseInt(uid);
			int Pid=Integer.parseInt(spid);
			int Stepid=Integer.parseInt(stepid);
			
			boolean isSave=is.saveResult(Stepid,Uid,Pid,hjqk,hqjgbz);
			if( isSave){
				model.addAttribute("message","获取结果成功");
			}else
				model.addAttribute("message","获取结果失败");
			
			//获取子项目信息
			Product01Service p1s = new Product01ServiceImp();
			SubProject subpro=new SubProject();
			subpro=p1s.getsubpro(Uid, Pid);
			model.addAttribute("subpro",subpro);
			//获取流程信息
			List<SubProjectStep> list=is.getLiucheng(Integer.parseInt(spid));
			model.addAttribute("steplist",list);
			model.addAttribute("uid",uid);
			model.addAttribute("spid",spid);
			model.addAttribute("stepid",stepid);
			//打印本函数日志结果
			is.printlog("detail",uid,spid,stepid,list);
			
			return show_result(spid,stepid,model,req);
			
		}

		
		//写，获取结果
		@RequestMapping(value="/test",method=RequestMethod.GET)
		public String test1(){
			
			return "pay/pay";
			
		}
	
}
